

//
let dateFormat1 = function (str) {
  return str ? str.substr(0, 4) + '.' + str.substr(4, 2) + '.' + str.substr(6, 2) : ''
};
let dateFormat2 = function (str) {
  return str ? str.substr(0, 4) + '/' + str.substr(4, 2) + '/' + str.substr(6, 2) : ''
};
let dateFormatYMDHM = function (str) {
  return str ? str.substr(0, 4) + '/' + str.substr(4, 2) + '/' + str.substr(6, 2) + ' ' + str.substr(8, 2) + ':' + str.substr(10, 2) : ''
};
let dateFormatYMDHM2 = function (str) {
  return str ? str.substr(0, 4) + '-' + str.substr(4, 2) + '-' + str.substr(6, 2) + ' ' + str.substr(8, 2) + ':' + str.substr(10, 2) : ''
};
let dateStrFormat12 = function (dateStr) {
  if (dateStr) {
    let tmpStr = dateStr.replace(/[\-\:]+|\s+/g, "")
    //return tmpStr.length===8?tmpStr+"000000":tmpStr
    return tmpStr
  } else {
    return ""
  }
};
let dateObjFormatYMDHM = function(date){
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  const hour = date.getHours();
  const minute = date.getMinutes();
  const second = date.getSeconds();
  return [year, month, day].map((n) => {
      n = n.toString();
      return n[1] ? n : '0' + n;
  }).join('/') + ' ' + [hour, minute, second].map((n) => {
      n = n.toString();
      return n[1] ? n : '0' + n;
  }).join(':');
}
let dateObjFormatYMDHM2 = function(date){
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  const hour = date.getHours();
  const minute = date.getMinutes();
  const second = date.getSeconds();
  return [year, month, day].map((n) => {
      n = n.toString();
      return n[1] ? n : '0' + n;
  }).join('-') + ' ' + [hour, minute, second].map((n) => {
      n = n.toString();
      return n[1] ? n : '0' + n;
  }).join(':');
}
let dateObjFormatYMD = function(date){
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();
  return [year, month, day].map((n) => {
      n = n.toString();
      return n[1] ? n : '0' + n;
  }).join('/');
}
let dateObjFormatYMD2 = function(date) { // 年月日插件值转换
  var val = date.getMonth() + 1;
  var monthVal = val < 10 ? '0' + val : '' + val;
  var yearVal = date.getFullYear();
  var val1 = date.getDate();
  var dayVal = val1 < 10 ? '0' + val1 : '' + val1;
  //console.log(dayVal);
  return yearVal + '' + monthVal + '' + dayVal;
};


module.exports = {
  dateFormat1,
  dateFormat2,
  dateFormatYMDHM,
  dateFormatYMDHM2,
  dateStrFormat12,
  dateObjFormatYMDHM,
  dateObjFormatYMDHM2,
  dateObjFormatYMD,
  dateObjFormatYMD2
}